// home/enterprise/Enterprise.js
import api from "../../utils/api.js";
import utils from "../../utils/utils.js";
import network from "../../utils/network.js";
import formatDate from "../../utils/format_date.js";
const app = getApp();


Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab: {
      list: [{
        id: 0,
        title: "简介"
      }, /*{
        id: 1,
        title: "新闻中心",
      }, */{
      //   id: 1,
      //   title: "产品中心"
      // }, {
        id: 1,
        title: "联系我们"
      }],
      selectedId: 0,
      scroll: false
    },
    activityIndex: 0,
    autoplay: true,
    interval: 5000,
    duration: 300,
    vertical: true,
    indicatorDots: true,
    circular: true,
    winWidth: 0, // 屏宽
    advBananer: ['http://image.document.guanmai.cn/1550825052828.png',
      'http://image.document.guanmai.cn/1550825052828.png'
    ],
    details: null,
    chanpin: [],
    expert: [{
      name: 'XXX',
      type: 'xxx',
      classes: 'xxxxxxx'
    }, {
      name: 'XXX',
      type: 'xxx',
      classes: 'xxxxxxx'
    }, {
      name: 'XXX',
      type: 'xxx',
      classes: 'xxxxxxx'
    }, {
      name: 'XXX',
      type: 'xxx',
      classes: 'xxxxxxx'
    }],
    markers: [{
      iconPath: "/resources/others.png",
      id: 0,
      latitude: 23.099994,
      longitude: 113.324520,
      width: 50,
      height: 50,
      label: {
        content: 'XXX',
        borderRadius: 5,
        bgColor: '#fff',
        padding: 10
      }
    }],
    type: null,
    url: app.globalData.url
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.setNavigationBarTitle({
      title: options.name
    })

    this.data.type = options.type;
    network.postJson(this, api.getQiyeDetails, {
      adminid: app.globalData.userInfo.uid,
      token: app.globalData.userInfo.token,
      id: options.id
    }).then(res => {
      this.setData({
        details: res.data.data.info,
        chanpin: res.data.data.chanpin
      })
    })
    this.toast = this.selectComponent("#toast");
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },

  /**
   * 点击tab
   */
  tabTapChange: function(e) {
    this.setData({
      activityIndex: e.detail.index,
      'tab.selectedId': e.detail.selectedId
    })
  },

  followTap() {
    // 已关注，这是取消关注
    network.postJson(this, api.follow, {
      adminid: app.globalData.userInfo.uid,
      token: app.globalData.userInfo.token,
      followid: this.data.details.id,
      followtype: 'qiye'
    }).then(res => {
      if (this.data.details.isfollow) {
        this.toast.showToast('取消成功');
      } else {
        this.toast.showToast('关注成功');
      }
      this.setData({
        'details.isfollow': !this.data.details.isfollow
      })
      // notification.postNotificationName('MyCollection');
    })
  },

  callTap() {
    let hotline = this.data.details.hotline
    wx.makePhoneCall({
      phoneNumber: hotline
    })
  },

  goPolicyDetails() {
    wx.navigateTo({
      url: '/policy/policy/PolicyDetails'
    })
  },

  goProductDetails(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/home/enterprise/ProductDetails?id=' + id
    })
  }


})